<extend name="public@base5"/>
<block name="head">
    <link rel="stylesheet" href="__STATIC__/css/mall.css?v={$_static_version}"></link>
</block>
<block name="main">
    
    <div class="wrap">
        <ul class="nav nav-tabs">
                <li class="nav-item">
                        <a class="nav-link" href="{:url('Store/subIndex',['type'=>$store_type])}">商品列表</a>
                </li>
                <li class="nav-item">
                        <a class="nav-link active" href="#">{$item_name} 库存/价格</a>
                </li>
        </ul>
    </div>
    
    <div class="wrap row mt-2">
        <foreach name="attr_item" item="attr">
            <div class="col-4 col-md-6 mt-2">
                <div class="card">
                    <div class="card-header">{$attr.name}
                        <div style="position: relative;float: right">
                        <if condition='$attr.main'>
                            <a class="btn btn-outline-danger disabled btn-xs" href="#">
                            <i class="fa fa-trash-o"></i>
                            </a>
                            <a title="取消规格属性" 
                               data-method="POST"
                               data-href="admin/attrs/main/{$attr.attr_id}/0" 
                               data-msg="是否取消商品规格" class="js-ajax-delete btn btn-danger btn-xs"><i class="fa fa-flag"></i></a>
                        <else/>
                            <a class="btn js-ajax-delete btn-danger btn-xs" title="删除" href="{:url('dela',['id'=>$attr.attr_id])}">
                            <i class="fa fa-trash-o"></i>
                            </a>
                            <a title="设置为规格属性,配置价格和库存" 
                               data-method="POST"
                               data-href="admin/attrs/main/{$attr.attr_id}/1" 
                               data-msg="是否设置为商品规格" class="js-ajax-delete btn btn-primary btn-xs"><i class="fa fa-check"></i></a>
                        </if>
                        </div>
                    </div>
                    <div class="m-3">
                        <div>
                            <form class="form js-ajax-form" action="admin/attrs" method="post">
                                <input type="hidden" name="item_id" value="{$id}">
                                <input type="hidden" name="id" value="{$attr.attr_id}">
                                <div class="input-group">
                                    <div class="input-group-text">
                                        <label class="input-group-addon">属性名称</label>
                                        <label>
                                            <input name="attr_name" type="text" class="form-control" value="{$attr.name}">
                                        </label>
                                        <button type="submit" class="btn btn-primary js-ajax-submit"><i class="fa fa-save"></i></button>
                                        
                                        
                                    </div>
                                </div>
                            </form>
                            <foreach name="attr['value']" item="value">
                                <form class="form js-ajax-form" action="admin/attrs/value" method="post">
                                <div class="input-group">
                                    <div class="input-group-text">
                                        
                                            <input name="item_id" type="hidden" value="{$id}">
                                            <input name="id" type="hidden" value="{$value.id}">
                                            <label>
                                                <input name="attr_value" type="text" class="form-control" value="{$value.value}"/>
                                            </label>
                                            
                                            <label class="input-group-addon">排序</label>
                                            <label>
                                                <input style='width:60px' disabled name="attr_value" type="text" class="form-control" value="{$value.order_id}"/>
                                            </label>
                                            <a class="btn js-ajax-delete" data-msg="是否修改顺序" href="{:url('order',['dir'=>1,'aid'=>$attr.attr_id,'vid'=>$value.id])}">
                                                <i class="fa fa-arrow-down"></i>
                                            </a>
                                            <a class="btn js-ajax-delete" data-msg="是否修改顺序" href="{:url('order',['dir'=>-1,'aid'=>$attr.attr_id,'vid'=>$value.id])}">
                                                <i class="fa fa-arrow-up"></i>
                                            </a>
                                            <a class="btn js-ajax-delete btn-danger" href="{:url('delv',['id'=>$value.id])}">
                                                <i class="fa fa-trash-o"></i>
                                            </a>
                                            
                                            <button type="submit" class="form-control js-ajax-submit btn btn-success" style="width: auto"><i class="fa fa-save"></i></button>
                                       
                                       
                                       
                                    </div>
                                </div>
                                </form>
                            </foreach>
                            <form class="form js-ajax-form" action="admin/attrs/value" method="post">
                                <div class="input-group">
                                    <div class="input-group-text">
                                        <input name="item_id" type="hidden" value="{$id}">
                                        <input name="attr_id" type="hidden" value="{$attr.attr_id}">
                                        <label>
                                            <input name="attr_value" type="text" class="form-control" value="">
                                        </label>
                                        <button type="submit" class="form-control js-ajax-submit btn btn-primary"><i class="fa fa-plus"></i> 添加新选项</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </foreach>
        <notEmpty name="attr_map">
        <div class="col-4 col-md-6 mt-2">
            <div class="card">
                <div class="card-header"><h3 class="panel-title">设置价格,库存</h3></div>
                <div class="panel-body">
                    <form class="form js-ajax-form" action="admin/attrs" method="post">
                        <input type="hidden" name="item_id" value="{$id}">
                        <foreach name="attr_map" item="map">
                        <div class="input-group mt-1">
                            <div class="input-group-text">
                            <label for="attr_name" style='width:260px'  class="input-group">{$map.name}</label>
                            <label class="input-group-addon">价格:</label>
                            <lable>
                                <input data-item_id="{$id}" data-id="{$map.id}"
                                       style='width:160px' type="number" name="price" class="form-control js-set_value" data-old="{$map.price}" value="{$map.price}"/>
                            </lable>
                            <label class="input-group-addon">库存:</label>
                            <lable>
                                <input data-item_id="{$id}" style='width:200px' data-id="{$map.id}" type="number" name="count" class="form-control js-set_value" data-old="{$map.count}" value="{$map.count}"/>
                            </lable>
                            </div>
                            <button type="button" class="btn btn-primary js-ajax-submit" onclick="alert('保存成功')">保存</button>
                        </div>
                        </foreach>
                    </form>
                </div>
            </div>
        </div>
        </notEmpty>
        
        <div class="col-4 col-md-6  mt-2">
            <div class="card">
                <div class="card-header"><h3 class="panel-title">添加新属性</h3></div>
                <div class="panel-body">
                    <form class="form js-ajax-form" action="admin/attrs" method="post">
                        <input type="hidden" name="item_id" value="{$id}">
                        <div class="input-group">
                            <div class="input-group-text">
                                <label for="attr_name" class="input-group">属性名称</label>
                                <input name="attr_name" type="text" class="form-control" id="attr_name" placeholder="请输入属性名称">
                            </div>
                             
                             <button type="submit" class="btn btn-primary js-ajax-submit">创建新属性</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="scripts">
    <script src="__STATIC__/js/mall.js"></script>
</block>
